<?php

namespace App\Http\Controllers\PC\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Service\Statistic\StatisticService;
use Session;
use Config;

class HomeController extends Controller
{
    private $statistic;
    private $params = [];

    public function __construct(StatisticService $statistic)
    {
        $this->statistic = new StatisticService();
    }


    public function index(Request $request)
    {

        try{
            $url = url()->full();
            if(array_key_exists('query', parse_url($url)) && !Session::get(Config::get('custom.setting.MEMBER_UNQUIE_CODE')) )
            {
                $this->params['url'] = $url;
                $this->params['action'] = 'click'; // 点击
                $this->params['terminal_id'] = 2;  //  PC端
                $this->params['status'] = '1';       //  状态
                $this->params['ip'] = $request->getClientIp();  //  客户端IP
                $this->params['code'] = time();  //  客户端IP
                $this->statistic->Statictis($this->params);
                Session::put(Config::get('custom.setting.MEMBER_QUERY'),$url);
                Session::put(Config::get('custom.setting.MEMBER_UNQUIE_CODE'),$this->params['code']);
            }
        }catch (\Exception $exception){

        }
        $title='首页';
        $number = 0;
       return view('PC.Home.index')->with('title',$title)->with('number',$number);
    }

    /**
     * @param Request $request
     * 推广咨询
     */
    public function ExtensionConsultation(Request $request)
    {
        if(Session::get(Config::get('custom.setting.MEMBER_QUERY')))
        {
            $this->params['url'] = Session::get(Config::get('custom.setting.MEMBER_QUERY'));
            $this->params['code'] = Session::get(Config::get('custom.setting.MEMBER_UNQUIE_CODE'));
            $this->params['action'] = 'consultation';   // 咨询
            $this->params['terminal_id'] = 2;  //  PC端
            $this->params['status'] = '1';  //  PC端
            $this->params['ip'] = $request->getClientIp();  //  客户端IP
            $this->statistic->Statictis($this->params);
        }
    }
    




}
